package com.damu.xiaomi.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Fou Jack of all trades and master of none.
 * @date 2022/3/18 11:18
 */
public class ResponseMessage {
    //错误码
    private String errorCode;
    //错误信息描述
    private String errorMsg;
    //Map存放需要的对象，用来返回数据
    private Map<String,Object> objectMap = new HashMap<>();

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Map<String, Object> getObjectMap() {
        return objectMap;
    }

    public void setObjectMap(Map<String, Object> objectMap) {
        this.objectMap = objectMap;
    }
    //向HashMap里快速添加对象的方法
    public ResponseMessage addObject(String key,Object value){
        this.objectMap.put(key, value);
        return this;
    }
    //处理成功时的方法
    public static ResponseMessage success(){
        ResponseMessage rm = new ResponseMessage();
        rm.setErrorCode("100");
        rm.setErrorMsg("处理成功喽！");
        return  rm;
    }

    //处理失败时的方法
    public static ResponseMessage error(){
        ResponseMessage rm = new ResponseMessage();
        rm.setErrorCode("200");
        rm.setErrorMsg("处理失败了！");
        return  rm;
    }

}
